inspector: Add frame clock info
authorMatthias Clasen <mclasen@redhat.com>
Thu, 13 Nov 2014 03:50:52 +0000 (22:50 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 13 Nov 2014 03:52:59 +0000 (22:52 -0500)
Add the frame clocks of toplevel widgets to the object tree,
and show their frame count and frame rate in the misc tab.

gtk/inspector/misc-info.c
gtk/inspector/misc-info.ui
gtk/inspector/misc-info.ui.h
gtk/inspector/object-tree.c

index 08343119f0787647a929df4f8af30c3a390263b0..323f6d5e1de3a5bb95dc3b8c9a06d032d13f64fe 100644 (file)
@@ -56,6 +56,10 @@ struct _GtkInspectorMiscInfoPrivate {
   GtkWidget *clip_area;
   GtkWidget *tick_callback_row;
   GtkWidget *tick_callback;
+  GtkWidget *framerate_row;
+  GtkWidget *framerate;
+  GtkWidget *framecount_row;
+  GtkWidget *framecount;
   GtkWidget *accessible_role_row;
   GtkWidget *accessible_role;
   GtkWidget *mapped_row;
@@ -68,6 +72,7 @@ struct _GtkInspectorMiscInfoPrivate {
   GtkWidget *child_visible;
 
   guint update_source_id;
+  gint64 last_frame;
 };
 
 enum
@@ -324,6 +329,43 @@ update_info (gpointer data)
       update_focus_widget (sl);
     }
 
+  if (GDK_IS_FRAME_CLOCK (sl->priv->object))
+    {
+      GdkFrameClock *clock;
+      gint64 frame;
+      gint64 frame_time;
+      gint64 history_start;
+      gint64 history_len;
+      gint64 previous_frame_time;
+      GdkFrameTimings *previous_timings;
+
+      clock = GDK_FRAME_CLOCK (sl->priv->object);
+      frame = gdk_frame_clock_get_frame_counter (clock);
+      frame_time = gdk_frame_clock_get_frame_time (clock);
+
+      tmp = g_strdup_printf ("%ld", frame);
+      gtk_label_set_label (GTK_LABEL (sl->priv->framecount), tmp);
+      g_free (tmp);
+
+      history_start = gdk_frame_clock_get_history_start (clock);
+      history_len = frame - history_start;
+
+      if (history_len > 0 && sl->priv->last_frame != frame)
+        {
+          previous_timings = gdk_frame_clock_get_timings (clock, history_start);
+          previous_frame_time = gdk_frame_timings_get_frame_time (previous_timings);
+          tmp = g_strdup_printf ("%4.1f ⁄ s", (G_USEC_PER_SEC * history_len) / (double) (frame_time - previous_frame_time));
+          gtk_label_set_label (GTK_LABEL (sl->priv->framerate), tmp);
+          g_free (tmp);
+        }
+      else
+        {
+          gtk_label_set_label (GTK_LABEL (sl->priv->framerate), "—");
+        }
+
+      sl->priv->last_frame = frame;
+    }
+
   return G_SOURCE_CONTINUE;
 }
 
@@ -402,6 +444,17 @@ gtk_inspector_misc_info_set_object (GtkInspectorMiscInfo *sl,
       gtk_widget_hide (sl->priv->focus_widget_row);
     }
 
+  if (GDK_IS_FRAME_CLOCK (object))
+    {
+      gtk_widget_show (sl->priv->framecount_row);
+      gtk_widget_show (sl->priv->framerate_row);
+    }
+  else
+    {
+      gtk_widget_hide (sl->priv->framecount_row);
+      gtk_widget_hide (sl->priv->framerate_row);
+    }
+
   update_info (sl);
 }
 
@@ -511,6 +564,10 @@ gtk_inspector_misc_info_class_init (GtkInspectorMiscInfoClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, clip_area);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, tick_callback_row);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, tick_callback);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framecount_row);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framecount);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framerate_row);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, framerate);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, accessible_role_row);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, accessible_role);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMiscInfo, mapped_row);
index 4eeba49c8c245b265c1b96e9f844c81c5d4c294a..d0a79664148574ba440ac29717209eef580b201a 100644 (file)
                   </object>
                 </child>
 
+                <child>
+                  <object class="GtkListBoxRow" id="framecount_row">
+                    <property name="visible">true</property>
+                    <property name="activatable">false</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="visible">true</property>
+                        <property name="orientation">horizontal</property>
+                        <property name="margin">10</property>
+                        <property name="spacing">40</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">true</property>
+                            <property name="label" translatable="yes">Frame count</property>
+                            <property name="halign">start</property>
+                            <property name="valign">baseline</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="expand">true</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="framecount">
+                            <property name="visible">true</property>
+                            <property name="halign">end</property>
+                            <property name="valign">baseline</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+
+                <child>
+                  <object class="GtkListBoxRow" id="framerate_row">
+                    <property name="visible">true</property>
+                    <property name="activatable">false</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="visible">true</property>
+                        <property name="orientation">horizontal</property>
+                        <property name="margin">10</property>
+                        <property name="spacing">40</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">true</property>
+                            <property name="label" translatable="yes">Frame rate</property>
+                            <property name="halign">start</property>
+                            <property name="valign">baseline</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="expand">true</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="framerate">
+                            <property name="visible">true</property>
+                            <property name="halign">end</property>
+                            <property name="valign">baseline</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+
                 <child>
                   <object class="GtkListBoxRow" id="accessible_role_row">
                     <property name="visible">true</property>
index 53fba2b42a70876d5051468ef347a2325b5adf62..a09a285e51989c5fd0f9ba89752c35fe1dec4158 100644 (file)
@@ -9,6 +9,8 @@ N_("Mnemonic Label");
 N_("Allocated size");
 N_("Clip area");
 N_("Tick callback");
+N_("Frame count");
+N_("Frame rate");
 N_("Accessible role");
 N_("Mapped");
 N_("Realized");
index 6f7d0bc51337e5a3824d51f3b53f843a620616d9..000db9171b3a52fcd61dfa8bff95e972ca413410 100644 (file)
@@ -780,6 +780,15 @@ gtk_inspector_object_tree_append_object (GtkInspectorObjectTree *wt,
             }
           g_list_free (list);
         }
+
+       if (gtk_widget_is_toplevel (GTK_WIDGET (object)))
+         {
+           GObject *clock;
+
+           clock = (GObject *)gtk_widget_get_frame_clock (GTK_WIDGET (object));
+           if (clock)
+             gtk_inspector_object_tree_append_object (wt, clock, &iter, "frame-clock");
+         }
     }
 }